package algo;

import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;

import data.Mail;

public class SpamMeanNearNeighborsEvaluator implements NearNeighborsEvaluator
{
	private static final SpamMeanNearNeighborsEvaluator instance =  new SpamMeanNearNeighborsEvaluator();
	
	private SpamMeanNearNeighborsEvaluator()
	{
		
	}
	
	public static SpamMeanNearNeighborsEvaluator getInstance()
	{
		return instance;
	}
	
	@Override
	public double evaluate(Collection<? extends Entry<Double, Mail>> simiarities)
	{
		double evaluation;
		int spam = 0;
		for (Map.Entry<Double, Mail> entry : simiarities)
		{
			//double similarity = entry.getKey();
			Mail mail = entry.getValue();
			//System.out.println(similarity + " : " + mail);
			if (mail.isSpam())
			{
				spam++;
			}
		}
		//System.out.println(spam + " >< " + nspam);
		//System.out.println("simiarities.size() : " + simiarities.size());
		evaluation = (double) spam / simiarities.size();
		return evaluation;
	}

}
